<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_dev_users=new dev_users();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["id_user"])){$_dev_users->set_id_user($_POST["id_user"]);}
		if(isset($_POST["type_user"])){$_dev_users->set_type_user($_POST["type_user"]);}
		if(isset($_POST["id_inscription"])){$_dev_users->set_id_inscription($_POST["id_inscription"]);}
		if(isset($_POST["username"])){$_dev_users->set_username($_POST["username"]);}
		if(isset($_POST["passwd"])){$_dev_users->set_passwd($_POST["passwd"]);}
		if(isset($_POST["is_connected"])){$_dev_users->set_is_connected($_POST["is_connected"]);}
		$res=$_dev_users->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["id_user"])){
		$_dev_users->set_id_user($_POST["id_user"]);
		$res=$_dev_users->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["id_user"])){$_dev_users->set_id_user($_POST["id_user"]);}
		if(isset($_POST["type_user"])){$_dev_users->set_type_user($_POST["type_user"]);}
		if(isset($_POST["id_inscription"])){$_dev_users->set_id_inscription($_POST["id_inscription"]);}
		if(isset($_POST["username"])){$_dev_users->set_username($_POST["username"]);}
		if(isset($_POST["passwd"])){$_dev_users->set_passwd($_POST["passwd"]);}
		if(isset($_POST["is_connected"])){$_dev_users->set_is_connected($_POST["is_connected"]);}
		$res=$_dev_users->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["id_user"]) && !empty($_POST["id_user"])){
		$constraint.=" AND id_user='".$_POST["id_user"]."'";
	}

	if(isset($_POST["type_user"]) && !empty($_POST["type_user"])){
		$constraint.=" AND type_user='".$_POST["type_user"]."'";
	}

	if(isset($_POST["id_inscription"]) && !empty($_POST["id_inscription"])){
		$constraint.=" AND id_inscription='".$_POST["id_inscription"]."'";
	}

	if(isset($_POST["username"]) && !empty($_POST["username"])){
		$constraint.=" AND username='".$_POST["username"]."'";
	}

	if(isset($_POST["passwd"]) && !empty($_POST["passwd"])){
		$constraint.=" AND passwd='".$_POST["passwd"]."'";
	}

	if(isset($_POST["is_connected"]) && !empty($_POST["is_connected"])){
		$constraint.=" AND is_connected='".$_POST["is_connected"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_dev_users->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_dev_users->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>